package com.demo.rocketmq.consumer;

import com.alibaba.fastjson.JSON;
import com.demo.rocketmq.entity.CanalResult;
import com.demo.rocketmq.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author K
 */
@Component
@Slf4j
@RocketMQMessageListener(topic = "user_topic", consumerGroup = "canal_consumer_group")
public class CanalConsumer implements RocketMQListener<CanalResult<User>> {

    @Override
    public void onMessage(CanalResult<User> canalResult){
        log.info("canal result：{}", JSON.toJSONString(canalResult));
        List<User> data = canalResult.getData();
        data.forEach(s -> log.info("userName:{}， userId:{}", s.getUserName(), s.getUserId()));
    }
}
